<template>
  <!--最外层div  -->
  <div style="width: 100%;">
<!-- 添加用户的弹出窗   -->
    <el-dialog
      title="添加用户"
      :visible.sync="addVisible"
      width="40%"
      :before-close="handleClose1">
<!--      添加弹窗的三个输入框-->
      <div style="height: 230px;">
        <el-form :model="form">
<!--         第一个输入框 -->
          <div>
            <el-form-item label="手机号：" :label-width="formLabelWidth" style="width: 150px;">
              <el-input placeholder="请选择用户" v-model="input4" :disabled="true" style="width: 300px;" >
                <template slot="append"><el-button icon="el-icon-search" @click="findVisible=true"></el-button></template>
              </el-input>
            </el-form-item>
          </div>
<!--          第二个输入框-->
          <div style="padding-top: 15px">
            <el-form-item label="名                称：" :label-width="formLabelWidth" style="width: 150px;">
              <el-input placeholder="请输入名称" v-model="input2" style="width: 300px;" ></el-input>
            </el-form-item>
          </div>
<!--          第三个输入框-->
          <div style="line-height: 70px">
            <el-form-item label="备                注：" :label-width="formLabelWidth" style="width: 150px;">
              <el-input type="textarea" v-model="form.desc" style="width: 300px;"></el-input>
            </el-form-item>
          </div>
        </el-form>
      </div>
<!--      添加用户弹窗中的两个按钮-->
      <div  style="padding-top: 10px;float: right;height: 300px; position: relative;bottom: 30px">
        <el-button @click="addVisible = false">取 消</el-button>
        <el-button type="primary" @click="addVisible = false">确 定</el-button>
      </div>
    </el-dialog>


<!--    搜索用户的弹窗-->
    <el-dialog
      title="用户列表"
      :visible.sync="findVisible"
      width="70%"
      :before-close="handleClose2">
      <!--  头部按钮  输入框-->
      <div>
        <form>
<!--          左侧的文字和输入框-->
          <div style="float: left">
            <label style="width: 150px;">手机号：</label>
            <el-input v-model="input3" placeholder="请输入内容" size="small"  style="width: 180px; padding-right: 15px"></el-input>
          </div>
<!--          右侧的两个按钮-->
          <div style="float: left">
            <el-button type="primary" icon="el-icon-search" size="small"  style="width: 72px; ">查询</el-button>
            <el-button plain  size="small"  style="width: 72px; ">重置</el-button>
          </div>
        </form>
      </div>

<!--      表格————用户数据-->
      <div style="padding-top: 50px;">
          <el-table
            :data="userTable"
            border
            style="width: 100%">
            <el-table-column
              prop="date"
              label="日期"
              width="180">
            </el-table-column>
            <el-table-column
              prop="name"
              label="姓名"
              width="180">
            </el-table-column>
            <el-table-column
              prop="address"
              label="地址">
            </el-table-column>
          </el-table>
      </div>
      <!--      搜索用户弹窗中的按钮-->
      <div style="padding-top: 30px">
        <el-pagination
          @size-change="handleSizeChange3"
          @current-change="handleCurrentChange3"
          :current-page="currentPage2"
          :page-sizes="[100, 200, 300, 400]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="400">
        </el-pagination>
      </div>
    </el-dialog>





<!--    修改信息弹窗-->
    <el-dialog
      title="用户修改信息"
      :visible.sync="updateVisible"
      width="40%"
      :before-close="handleClose3">
      <div style="height: 280px;">
        <form>
          <!--         第一个输入框 不可更改-->
          <div>
            <span>用户手机：</span>
            <el-input v-model="input5" :disabled="true" style="width: 300px;" ></el-input>
          </div>
          <!--          第二个输入框  可改-->
          <div style="padding-top: 15px">
            <span>名&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp称：</span>
            <el-input placeholder="请输入名称" v-model="input1" style="width: 300px;" ></el-input>
          </div>
          <!--     第三个输入框   计数器     -->
          <div style="padding-top: 15px">
            <span>排&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp序：</span>
            <el-input-number v-model="num" @change="handleChange" :min="1" :max="10" style="width: 300px;"></el-input-number>
          </div>
          <!--          第三个输入框-->
          <div style="line-height: 70px">
            <span>备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注：</span>
            <el-input type="textarea" v-model="form.desc" style="width: 300px;"></el-input>
          </div>
        </form>
      </div>

      <!--      修改信息弹窗弹窗中的两个按钮-->
      <div>
        <div  style="padding-top: 10px;float: right;height: 300px; position: relative;bottom: 30px">
          <el-button @click="updateVisible = false">取 消</el-button>
          <el-button type="primary" @click="updateVisible = false">确 定</el-button>
        </div>
      </div>

    </el-dialog>


<!--    设置角色的弹窗-->

    <el-dialog
      title="用户设置角色"
      :visible.sync="dialogVisible"
      width="70%"
      :before-close="handleClose4">
     <!--   设置角色弹窗中头部按钮   -->
      <div>
        <form>
          <div style="float: left;margin-left: 20px">
            <label style="width: 150px;">角色：</label>
            <el-input v-model="input" placeholder="请输入内容" size="small"  style="width: 180px; padding-right: 15px"></el-input>
          </div>
          <div style="float: left">
            <el-button type="primary" icon="el-icon-search" size="small"  style="width: 72px; ">查询</el-button>
            <el-button plain  size="small"  style="width: 72px; ">重置</el-button>
            <el-button type="primary"  size="small" style="width:72px;" >设置角色</el-button>
          </div>
        </form>
      </div>
      <!--   设置角色弹窗中表格   -->
      <div style="padding-top: 50px">
        <el-table
          ref="multipleTable"
          :data="tableRoles"
          border
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            label="日期"
            width="120">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            width="120">
          </el-table-column>
          <el-table-column
            prop="address"
            label="地址"
            show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </div>
      <!--   设置角色弹窗中  最下面的分页   -->
      <div style="padding-top: 30px">
        <el-pagination
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"
          :current-page="currentPage3"
          :page-sizes="[100, 200, 300, 400]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="400">
        </el-pagination>
      </div>
    </el-dialog>


    <!-- 修改密码弹窗 -->
    <el-dialog
      title="用户密码修改"
      :visible.sync="updateMima"
      width="30%"
      :before-close="handleClose5">
     <!--   修改密码弹窗中的两个输入框   -->
      <el-form :model="form">
        <div>
          <el-form-item label="新   密   码：" :label-width="formLabelWidth" style="width: 150px;">
            <el-input v-model="input7" placeholder="请输入密码" show-password style="width: 180px"></el-input>
          </el-form-item>
        </div>
        <div style="padding-top: 20px">
          <el-form-item label="确认密码：" :label-width="formLabelWidth" style="width: 150px;">
            <el-input v-model="input8" placeholder="请再次输入密码" show-password style="width: 180px"></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div style="height: 50px;">
        <div  style="padding-top: 10px;float: right; position: relative;bottom: -10px">
          <el-button @click="updateMima = false">取 消</el-button>
          <el-button type="primary" @click="updateMima = false">确 定</el-button>
        </div>
      </div>
    </el-dialog>


    <!--  页面头部按钮  输入框-->
    <div>
      <form>
        <div style="float: left">
          <label style="width: 150px;">手机号：</label>
          <el-input v-model="input" placeholder="请输入内容" size="small"  style="width: 180px; padding-right: 15px"></el-input>

        </div>
        <div style="float: left">
          <el-button type="primary" icon="el-icon-search" size="small"  style="width: 72px; ">查询</el-button>
          <el-button plain  size="small"  style="width: 72px;padding-left: 15px ">重置</el-button>
          <el-button type="primary"  size="small" style="width: 72px; padding-left: 15px" @click="addVisible=true">添加</el-button>
        </div>
      </form>
    </div>
    <!-- 主页面的 表格-->
    <div style="width: 100%; padding-top: 50px">
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="uid"
          label="序号"
          width="50">
        </el-table-column>
        <el-table-column
          prop="uphone"
          label="手机号"
          width="170">
        </el-table-column>
        <el-table-column
          prop="uname"
          label="名称"
          width="230">
        </el-table-column>
        <el-table-column
          prop="排序"
          label="排序"
          width="80">
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="200">

        <!--   状态开关 组件 -->
          <template slot-scope="scope">
            <el-switch
              style="display: block"
              v-model="scope.row.statusId"
              @change="handleChangeStatus(scope.row,scope.row.statusId)"
              :active-value="0"
              :inactive-value="1"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="正常"
              inactive-text="禁用">
            </el-switch>
          </template>

        </el-table-column>
        <el-table-column
          prop="备注"
          label="备注"
          width="220">
        </el-table-column>
        <el-table-column
          prop="操作"
          label="操作">
          <!--操作列 的三个按钮-->
          <el-button type="danger"  size="mini" >删除</el-button>
          <el-button type="success" size="mini"  @click="updateVisible=true">修改</el-button>
          <el-button type="primary" size="mini"  @click="dialogVisible=true">设置角色</el-button>
          <el-button type="success" size="mini"  @click="updateMima=true">修改密码</el-button>
        </el-table-column>

      </el-table>
    </div>
    <!--  分页部分-->
    <div style="float: right ;padding-top: 20px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="50">
      </el-pagination>
    </div>
  </div>
</template>

<script>


import HelloWorld from "../../HelloWorld";
export default {
  name: "PowerMenu",
  components: {HelloWorld},
  data() {
    return {
      addVisible: false,/*添加弹窗*/
      findVisible:false,/*添加中的搜索用户弹窗*/
      updateVisible:false,/*修改弹窗*/
      dialogVisible:false,/*设置角色弹窗*/
      updateMima:false,/*修改密码弹窗*/
      currentPage: 4,  /*主页面分页  当前页默认值*/
      currentPage2:4,  /*搜索用户弹窗的分页  当前页默认值*/
      currentPage3:4,  /*设置角色弹窗中的分页  当前页默认值*/
      /*主页面表格数据  查询用户*/
      tableData: [],
      /*弹窗中弹窗--查询出的用户表数据  查询所有用户*/
      userTable: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
      }],
      /*设置角色中的表的数据    查询所有角色*/
      tableRoles:[
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }
      ],
      multipleSelection: [],
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      input: '',
      input1: '',
      input2: '',
      input3: '',
      input4: '',
      input5: '',
      input6: '',
      input7: '',
      input8: '',
      select: '',
      num:'',
      value2: true,
      formLabelWidth:'150px',
    }
  },
  methods: {
    handleChange(){},
    handleClose(done1){
      done1();
    },
    handleClose1(done1){
      done1();
    },
    handleClose2(done2){
      done2();
    },
    handleClose3(done3){
      done3();
    },
    handleClose4(done4){
      done4();
    },
    handleClose5(done5){
      done5();
    },
    //主页面的分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    //设置角色弹窗中的分页
    handleSizeChange2(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange2(val) {
      console.log(`当前页: ${val}`);
  },
    //搜索用户弹窗中的分页
    handleSizeChange3(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange3(val) {
      console.log(`当前页: ${val}`);
    },
    //禁用按钮
    handleChangeStatus(obj,statusId){
      const title = { 1: '禁用', 0: '启用' }
      this.$confirm(`确定要${title[statusId]}吗?`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableData.statusId=obj.statusId
      }).catch(() => {
        obj.statusId=(statusId+1)%2
      })
    },
    //设置角色中表格的方法  左侧多选框
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //主页面查询数据方法
    queryAllUser(){
        // this.$axios.get(`user/queryAllUser`).then(r => {
        //   alert(JSON.stringify(r));
        //   this.tableData = r.data;
        // })
    }


  },
  mounted() {
    this.queryAllUser();
  }
}
</script>

<style scoped>

</style>
